package com.Rolin.wss.service.impl;

import com.Rolin.wss.dao.UserMapper;
import com.Rolin.wss.model.UserAuthVO;
import com.Rolin.wss.model.UserRegisterVO;
import com.Rolin.wss.model.UserVO;
import com.Rolin.wss.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {
    //注入DAO依赖
    @Autowired
    private UserMapper userMapper;

    @Override
    public int verifyUser(UserAuthVO user) {
        String phone = user.getPhone();
        String pwd = user.getPwd();
        if (userMapper.verifyUserByPhoneAndPassword(phone,pwd)==null) {
            return -1;
        }
        else return userMapper.verifyUserByPhoneAndPassword(phone,pwd);
    }

    @Override
    public UserVO getUser(int id) {
        return userMapper.getUserById(id);
    }

    @Override
    public boolean registerUser(UserRegisterVO user) {
        Integer res = userMapper.insertUser(
                user.getUser_phone(),
                user.getUser_pwd(),
                user.getUser_age(),
                user.getUser_email(),
                user.getUser_special(),
                user.getUser_sex()
        );

        return res == 1;
    }
}
